home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / multiprocessing / __init__.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  8.1 KB  |  285 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '0.70a1'
  5. __all__ = [
  6.     'Process',
  7.     'current_process',
  8.     'active_children',
  9.     'freeze_support',
  10.     'Manager',
  11.     'Pipe',
  12.     'cpu_count',
  13.     'log_to_stderr',
  14.     'get_logger',
  15.     'allow_connection_pickling',
  16.     'BufferTooShort',
  17.     'TimeoutError',
  18.     'Lock',
  19.     'RLock',
  20.     'Semaphore',
  21.     'BoundedSemaphore',
  22.     'Condition',
  23.     'Event',
  24.     'Queue',
  25.     'JoinableQueue',
  26.     'Pool',
  27.     'Value',
  28.     'Array',
  29.     'RawValue',
  30.     'RawArray',
  31.     'SUBDEBUG',
  32.     'SUBWARNING']
  33. __author__ = 'R. Oudkerk (r.m.oudkerk@gmail.com)'
  34. import os
  35. import sys
  36. from multiprocessing.process import Process, current_process, active_children
  37. from multiprocessing.util import SUBDEBUG, SUBWARNING
  38.  
  39. class ProcessError(Exception):
  40.     pass
  41.  
  42.  
  43. class BufferTooShort(ProcessError):
  44.     pass
  45.  
  46.  
  47. class TimeoutError(ProcessError):
  48.     pass
  49.  
  50.  
  51. class AuthenticationError(ProcessError):
  52.     pass
  53.  
  54. import _multiprocessing
  55.  
  56. def Manager():
  57.     '''
  58.     Returns a manager associated with a running server process
  59.  
  60.     The managers methods such as `Lock()`, `Condition()` and `Queue()`
  61.     can be used to create shared objects.
  62.     '''
  63.     SyncManager = SyncManager
  64.     import multiprocessing.managers
  65.     m = SyncManager()
  66.     m.start()
  67.     return m
  68.  
  69.  
  70. def Pipe(duplex = True):
  71.     '''
  72.     Returns two connection object connected by a pipe
  73.     '''
  74.     Pipe = Pipe
  75.     import multiprocessing.connection
  76.     return Pipe(duplex)
  77.  
  78.  
  79. def cpu_count():
  80.     '''
  81.     Returns the number of CPUs in the system
  82.     '''
  83.     if sys.platform == 'win32':
  84.         
  85.         try:
  86.             num = int(os.environ['NUMBER_OF_PROCESSORS'])
  87.         except (ValueError, KeyError):
  88.             num = 0
  89.         except:
  90.             None<EXCEPTION MATCH>(ValueError, KeyError)
  91.         
  92.  
  93.     None<EXCEPTION MATCH>(ValueError, KeyError)
  94.     if 'bsd' in sys.platform or sys.platform == 'darwin':
  95.         
  96.         try:
  97.             num = int(os.popen('sysctl -n hw.ncpu').read())
  98.         except ValueError:
  99.             num = 0
  100.         except:
  101.             None<EXCEPTION MATCH>ValueError
  102.         
  103.  
  104.     None<EXCEPTION MATCH>ValueError
  105.     
  106.     try:
  107.         num = os.sysconf('SC_NPROCESSORS_ONLN')
  108.     except (ValueError, OSError, AttributeError):
  109.         num = 0
  110.  
  111.     if num >= 1:
  112.         return num
  113.     raise NotImplementedError('cannot determine number of cpus')
  114.  
  115.  
  116. def freeze_support():
  117.     '''
  118.     Check whether this is a fake forked process in a frozen executable.
  119.     If so then run code specified by commandline and exit.
  120.     '''
  121.     if sys.platform == 'win32' and getattr(sys, 'frozen', False):
  122.         freeze_support = freeze_support
  123.         import multiprocessing.forking
  124.         freeze_support()
  125.     
  126.  
  127.  
  128. def get_logger():
  129.     '''
  130.     Return package logger -- if it does not already exist then it is created
  131.     '''
  132.     get_logger = get_logger
  133.     import multiprocessing.util
  134.     return get_logger()
  135.  
  136.  
  137. def log_to_stderr(level = None):
  138.     '''
  139.     Turn on logging and add a handler which prints to stderr
  140.     '''
  141.     log_to_stderr = log_to_stderr
  142.     import multiprocessing.util
  143.     return log_to_stderr(level)
  144.  
  145.  
  146. def allow_connection_pickling():
  147.     '''
  148.     Install support for sending connections and sockets between processes
  149.     '''
  150.     reduction = reduction
  151.     import multiprocessing
  152.  
  153.  
  154. def Lock():
  155.     '''
  156.     Returns a non-recursive lock object
  157.     '''
  158.     Lock = Lock
  159.     import multiprocessing.synchronize
  160.     return Lock()
  161.  
  162.  
  163. def RLock():
  164.     '''
  165.     Returns a recursive lock object
  166.     '''
  167.     RLock = RLock
  168.     import multiprocessing.synchronize
  169.     return RLock()
  170.  
  171.  
  172. def Condition(lock = None):
  173.     '''
  174.     Returns a condition object
  175.     '''
  176.     Condition = Condition
  177.     import multiprocessing.synchronize
  178.     return Condition(lock)
  179.  
  180.  
  181. def Semaphore(value = 1):
  182.     '''
  183.     Returns a semaphore object
  184.     '''
  185.     Semaphore = Semaphore
  186.     import multiprocessing.synchronize
  187.     return Semaphore(value)
  188.  
  189.  
  190. def BoundedSemaphore(value = 1):
  191.     '''
  192.     Returns a bounded semaphore object
  193.     '''
  194.     BoundedSemaphore = BoundedSemaphore
  195.     import multiprocessing.synchronize
  196.     return BoundedSemaphore(value)
  197.  
  198.  
  199. def Event():
  200.     '''
  201.     Returns an event object
  202.     '''
  203.     Event = Event
  204.     import multiprocessing.synchronize
  205.     return Event()
  206.  
  207.  
  208. def Queue(maxsize = 0):
  209.     '''
  210.     Returns a queue object
  211.     '''
  212.     Queue = Queue
  213.     import multiprocessing.queues
  214.     return Queue(maxsize)
  215.  
  216.  
  217. def JoinableQueue(maxsize = 0):
  218.     '''
  219.     Returns a queue object
  220.     '''
  221.     JoinableQueue = JoinableQueue
  222.     import multiprocessing.queues
  223.     return JoinableQueue(maxsize)
  224.  
  225.  
  226. def Pool(processes = None, initializer = None, initargs = ()):
  227.     '''
  228.     Returns a process pool object
  229.     '''
  230.     Pool = Pool
  231.     import multiprocessing.pool
  232.     return Pool(processes, initializer, initargs)
  233.  
  234.  
  235. def RawValue(typecode_or_type, *args):
  236.     '''
  237.     Returns a shared object
  238.     '''
  239.     RawValue = RawValue
  240.     import multiprocessing.sharedctypes
  241.     return RawValue(typecode_or_type, *args)
  242.  
  243.  
  244. def RawArray(typecode_or_type, size_or_initializer):
  245.     '''
  246.     Returns a shared array
  247.     '''
  248.     RawArray = RawArray
  249.     import multiprocessing.sharedctypes
  250.     return RawArray(typecode_or_type, size_or_initializer)
  251.  
  252.  
  253. def Value(typecode_or_type, *args, **kwds):
  254.     '''
  255.     Returns a synchronized shared object
  256.     '''
  257.     Value = Value
  258.     import multiprocessing.sharedctypes
  259.     return Value(typecode_or_type, *args, **kwds)
  260.  
  261.  
  262. def Array(typecode_or_type, size_or_initializer, **kwds):
  263.     '''
  264.     Returns a synchronized shared array
  265.     '''
  266.     Array = Array
  267.     import multiprocessing.sharedctypes
  268.     return Array(typecode_or_type, size_or_initializer, **kwds)
  269.  
  270. if sys.platform == 'win32':
  271.     
  272.     def set_executable(executable):
  273.         '''
  274.         Sets the path to a python.exe or pythonw.exe binary used to run
  275.         child processes on Windows instead of sys.executable.
  276.         Useful for people embedding Python.
  277.         '''
  278.         set_executable = set_executable
  279.         import multiprocessing.forking
  280.         set_executable(executable)
  281.  
  282.     __all__ += [
  283.         'set_executable']
  284.  
  285.